<?php
// SLIDER SHORTCODE by iKarina & iGor - http://www.mojo-themes.com/user/iKarina/
// You CAN NOT copy and use this code in your themes
function slider( $atts, $content = null ) {
	global $width, $height;
	extract(shortcode_atts(array(
		'width'		=> '500',
		'height'		=> '',
		'autoplay'	=> '',
		'style'		=> 'default',
		'nav'			=> 'bottom',
		'float'		=> '',
		'transition'=> '',
		'circular'	=> ''
	), $atts));
	$slide = rand(9,9999);
	if ($width) {$w = 'width:'.$width.'px;'; $w100 = $width + 100;};
	if ($height) {$h = 'height:'.$height.'px;';};
	if ($float=="left") {$fl = ' float:left; margin:0 10px 10px 0;';} elseif ($float=="right") {$fl = ' float:right; margin:0 0 10px 10px;';};
	// MAIN WRAPPER
	if ($style=="default") {$wrapbefore = '<div class="wrapper-default" style="'.$w.$fl.'">'; $wrapafter = '</div>';}
		elseif ($style=="white") {$wrapbefore = '<div class="wrapper-white" style="'.$w.$fl.'">'; $wrapafter = '</div>';}
		elseif ($style=="gray") {$wrapbefore = '<div class="wrapper-gray" style="'.$w.$fl.'">'; $wrapafter = '</div>';};
	// TRANSITION
	if ($transition=="fade") {$trattr = 'speed:1, onBeforeSeek: before, onSeek: after,'; $trfunc = 'function before() { this.getRoot().stop().css({ opacity: "0.3" });}; function after() { this.getRoot().stop().animate({ opacity: "1" },200);}; ';}
		elseif ($transition=="slide") {$trattr = 'speed:500,';}
		elseif ($transition=="fadingslide") {$trattr = 'speed:500, onBeforeSeek: before, onSeek: after,'; $trfunc = 'function before() { this.getRoot().stop().css({ opacity: "0.3" });}; function after() { this.getRoot().stop().animate({ opacity: "1" },200);}; ';}
		else {$trattr = 'speed:1,';};
	// AUTOPLAY + CIRCULAR SCROLLING
	if ($autoplay) {$autoscroll = ".autoscroll({ autoplay: true, interval: ".$autoplay." })";};
	if ($circular=="yes") {$circ = '.circular()'; $indent = '$(".slider-'.$slide.'").find(".items").css({left:-'.$w100.'}); ';};
	if ($nav == 'bottom') {$navbottom = '<ul class="tabs-dots pt10 tabs-slider-'.$slide.' none"></ul><span class="pt10 fr"><button class="nextbutton next'.$slide.'"><span>Next &gt;</span></button></span>';}
		elseif ($nav == 'top') {$navtop = '<ul class="tabs-dots pb10 tabs-slider-'.$slide.' none"></ul><span class="pb10 fr"><button class="nextbutton next'.$slide.'"><span>Next &gt;</span></button></span><div class="clear"><!-- --></div>';};
	$before = $wrapbefore.$navtop.'<div class="shortslider slider-'.$slide.'" style="'.$w.$h.'"><div class="items">';
	$after = '</div></div>'.$navbottom.'
		<div class="clear"><!-- --></div>'.$wrapafter.'
		<div>
		<script type="text/javascript">
		var liqty = $(".slider-'.$slide.'").find(".item").size();
			for (i=1; i<=liqty; i++) {
				$(".tabs-slider-'.$slide.'").append(\'<li><a href="#fragment-\' + i + \'">&nbsp;</a></li>\');
			};
			if (liqty == 1) {
				$(".tabs-slider-'.$slide.'").css("display","none");
				$(".tabs-slider-'.$slide.'").next().css("display","none");
			};
			$(".slider-'.$slide.'").scrollable({size:1,
				'.$trattr.'
				clickable: false,
				next: ".next'.$slide.'"
			})'.$circ.'.navigator({
				navi: ".tabs-slider-'.$slide.'",
				naviItem: "li",
				activeClass: "tabs-dots-selected"
			})'.$autoscroll.';
			'.$trfunc.$indent.'
		</script>
		</div>
		<style type="text/css">.slider-'.$slide.' .items > div.item {'.$w.'}</style>
	';
	return $before.do_shortcode($content).$after;
	}
add_shortcode('slider', 'slider');

// SLIDER'S ITEMS
function slide( $atts, $content = null ) {
	global $width, $height;
	if ($width) {$videowidth = $width;} else {$videowidth = '500';};
	if ($height) {$videoheight = $height;} else {$videoheight = '344';};
	extract(shortcode_atts(array(
		'type'		=> '',
		'src'			=> '',
		'link'		=> '',
		'id'			=> '',
		'title'		=> '',
		'date'		=> '',
		'excerpt'	=> '',
		'thumb'		=> 'none',
		'thumbw'		=> '',
		'thumbh'		=> ''
	), $atts));
	// SLIDE AS IMAGE
	if ($type=="image") {
		if ($link) {$out = '<div class="item"><div><a href="'.$link.'"><img class="slideimg" src="'.$src.'" alt=""/></a></div></div>';}
		else {$out = '<div class="item"><div><img class="slideimg" src="'.$src.'" alt=""/></div></div>';}
	;}
	// SLIDE AS PAGE
	elseif ($type=="page") {
		if ($id) {
			$page_data = get_page($id);
			$content = $page_data->post_content;
			$out = '<div class="item"><div>'.do_shortcode($content).'</div></div>';
		}
		else {$out = '<div class="item"><div>An ID of page don\'t selected, e.g. <code>[slide type="page" id="5"]</code></div></div>';}
	;}
	// SLIDE AS POST
	elseif ($type=="post") {
		if ($id) {
			$post = get_post($id); setup_postdata($post);
				if ($title=="yes") {$h3 = '<h3><a href="'.get_permalink($id).'">'.$post->post_title.'</a></h3>';};			
				if ($date=="yes") {$time = '<div class="shortl"><span class="tim">'.get_the_time('M jS, Y').'</span></div>';};
				if ($excerpt=="yes") {$exc = '<p class="shexc">'.get_the_excerpt($post->ID).'</p><a href="'.get_permalink($post->ID).'" class="button">Read More</a>';};
				if ($thumbw || $thumbh) {
					// get a custom image of post
					$image2 = get_post_meta($id, 'full_image_value', true);
					// get a first image from body of post
					ob_start();
					ob_end_clean();
					$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
					$fi = $matches [1] [0];
					// set a parameters of dimentions
					if ($thumbw) {$thumbwidth = '&amp;w='.$thumbw; $thw = 'width="'.$thumbw.'"';};
					if ($thumbh) {$thumbheight = '&amp;h='.$thumbh; $thh = 'height="'.$thumbh.'"';};
					//CHECK IMAGE POST
					if ($image2) {$thumbnail = '<a href="'.get_permalink($id).'"><img class="thumb-'.$thumb.'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$image2.$thumbwidth.$thumbheight.'&amp;zc=1&amp;q=90" '.thw.thh.' alt="" /></a>';}
					//CHECK AUTOMATIC THUMB
					elseif ($fi<>"") {$thumbnail = '<a href="'.get_permalink($id).'"><img class="thumb-'.$thumb.'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$fi.$thumbwidth.$thumbheight.'&amp;zc=1&amp;q=90" '.thw.thh.' alt="" /></a>';};
				};
				$out = '<div class="item"><div>'.$thumbnail.$h3.$time.$exc.'</div></div>';
		}
		else {$out = '<div class="item"><div>An ID of post don\'t selected, e.g. <code>[slide type="post" id="5"]</code></div></div>';}
	;}
	// SLIDE AS YOUTUBE
	elseif ($type=="youtube") {
		if ($id) {$out = '<div class="item"><div><object width="'.$videowidth.'" height="'.$videoheight.'"><param name="movie" value="http://www.youtube.com/v/'.$id.'?fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$id.'?fs=1" type="application/x-shockwave-flash" width="'.$videowidth.'" height="'.$videoheight.'" allowscriptaccess="always" allowfullscreen="true" wmode="opaque"></embed></object></div></div>';}
		else {$out='<div class="item"><div>An ID of YouTube video don\'t selected, e.g. <code>[slide type="youtube" id="pTTkTN_IIck"]</code>. <br/>Take a look video URL like this: <a href="http://www.youtube.com/watch?v=pTTkTN_IIck">http://www.youtube.com/watch?v=pTTkTN_IIck</a></div></div>';}
	;}
	// SLIDE AS VIMEO
	elseif ($type=="vimeo") {
		if ($id) {$out = '<div class="item"><div><iframe src="http://player.vimeo.com/video/'.$id.'" width="'.$videowidth.'" height="'.$videoheight.'" frameborder="0"></iframe></div></div>';}
		else {$out = '<div class="item"><div>An ID of Vimeo video don\'t selected, e.g. <code>[slide type="vimeo" id="5979501"]</code>. <br/>Take a look video URL like this: <a href="http://vimeo.com/5979501">http://vimeo.com/5979501</a></div></div>';}
	;}
	// DEFAULT
	else {$out = '<div class="item"><div>'.do_shortcode($content).'</code></div></div>';}
	return $out;
	}
add_shortcode('slide', 'slide');
?>